package com.wang.net;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class UDPClient {

	  
	private static final byte[] RECEIVE_BUFFER = new byte[1024];
	
	 private static final InetSocketAddress ADDRESS = new InetSocketAddress("127.0.0.1", 8088);
	 
	public static void main(String[] args) throws Exception{
		
		
		DatagramSocket socket = new DatagramSocket();
		DatagramPacket recePacket = new DatagramPacket(RECEIVE_BUFFER, RECEIVE_BUFFER.length);
		try(BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in))){
			String line;
			while((line=consoleReader.readLine())!=null){
				socket.send(new DatagramPacket(line.getBytes(),line.length(), ADDRESS));
				socket.receive(recePacket);
				System.out.println(new String(recePacket.getData(),0,recePacket.getLength()));
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		
	}
}
